package cn.qyd.javahash;

import java.util.Arrays;

/**
 * @author 邱运铎
 * @date 2024-03-07 11:59
 */
public class HashDemo {
    public static void main(String[] args) {
        String name = "邱运铎";
        //split根据指定字符串或者指定正则表达式规则对字符串进行切割
        System.out.println(Arrays.toString("邱运铎 .java.  后端开发工程师javas".split("java")));
        System.out.println("‘邱运铎’的自己计算hashcode: " + computedHash(name));
        System.out.println("’邱运铎‘调用String.tohashcode:" + name.hashCode());
    }

    public static int computedHash(String str) {
        int hashcode = 0;
        for(int i = 0; i < str.length(); i++) {
            hashcode = hashcode*31 + str.charAt(i);
        }

        return hashcode;
    }
}
